﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace SheepClock
{
    public partial class MainPage
    {
        private void colorButton_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            if (colorsList.Visibility == Visibility.Collapsed)
            {
                colorsList.Visibility = Visibility.Visible;
                PushImageDown(colorButton);
            }
            else
            {
                HideColorsList();
            }
        }

        private void alarmsButton_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            PushImageDown(sender as System.Windows.Shapes.Rectangle);
            HideColorsList();

            timer.Stop();
            SharedGraphicsDeviceManager.Current.GraphicsDevice.SetSharingMode(false);
            NavigationService.Navigate(new Uri("/AlarmsPage.xaml", UriKind.Relative));
        }

        private void settingsButton_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            PushImageDown(sender as System.Windows.Shapes.Rectangle);
            HideColorsList();

            timer.Stop();
            SharedGraphicsDeviceManager.Current.GraphicsDevice.SetSharingMode(false);
            NavigationService.Navigate(new Uri("/SettingsPage.xaml", UriKind.Relative));
        }

        private void button_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            PushImageDown(sender as System.Windows.Shapes.Rectangle);
        }

        private void PushImageDown(System.Windows.Shapes.Rectangle img)
        {
            Storyboard pushStoryboard = null;
            if (img == colorButton)
                pushStoryboard = (Storyboard)this.Resources["PushStoryboard1"];
            else if (img == alarmsButton)
                pushStoryboard = (Storyboard)this.Resources["PushStoryboard2"];
            else if (img == settingsButton)
                pushStoryboard = (Storyboard)this.Resources["PushStoryboard3"];

            if (pushStoryboard != null)
                pushStoryboard.Begin();
        }

        private void button_MouseLeft(object sender, System.Windows.Input.MouseEventArgs e)
        {
            PopImageBack(sender as System.Windows.Shapes.Rectangle);
        }

        private void PopImageBack(System.Windows.Shapes.Rectangle img)
        {
            Storyboard popBackStoryboard = null;
            if (img == colorButton)
                popBackStoryboard = (Storyboard)this.Resources["PopBackStoryBoard1"];
            else if (img == alarmsButton)
                popBackStoryboard = (Storyboard)this.Resources["PopBackStoryBoard2"];
            else if (img == settingsButton)
                popBackStoryboard = (Storyboard)this.Resources["PopBackStoryBoard3"];

            if (popBackStoryboard != null)
                popBackStoryboard.Begin();
        }
    }
}